#!/bin/bash

# prevent commit to the main branch
branch="$(git rev-parse --abbrev-ref HEAD)"

RED='\033[0;31m'       # Red
GREEN='\033[0;32m'     # Green
YELLOW='\033[0;33m'    # Yellow
BRED='\033[1;31m'      # Bold Red
BGREEN='\033[1;32m'    # Bold Green
BYELLOW='\033[1;33m'   # Bold Yellow
OFF='\033[0m'          # Text Color Reset

if [ "$branch" = "main" ]; then
  echo -e "${BYELLOW}[GIT WARNING]${OFF} You can't commit directly to the main branch"
  echo -e "${BYELLOW}[GIT WARNING]${OFF} Unstaging previously checked in files"
  git reset
  exit 1
fi

# format satged files if any
SCRIPT_PATH=${BASH_SOURCE[0]}
cd "$(dirname $(dirname $(dirname "$SCRIPT_PATH")))" && make -s format-staged-files
